package com.nexgo.payment.trans.download;

import android.support.annotation.NonNull;

import com.nexgo.data.entity.RecvData;
import com.nexgo.payment.aop.annotation.ManageTransCondition;
import com.nexgo.payment.constrant.TransType;
import com.nexgo.payment.databases.DataSource;
import com.nexgo.payment.entity.TransData;
import com.nexgo.payment.trans.AbsOnlinePresenter;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Timer;
import java.util.TimerTask;

import static com.google.common.base.Preconditions.checkNotNull;

/**
 * 风险交易报送
 *
 * @author xhj
 * @time 2018年08月1日
 */
@ManageTransCondition
public class RiskTradePresenter extends AbsOnlinePresenter implements DownloadTransContract.Presenter {
    private Logger mLog = LoggerFactory.getLogger(RiskTradePresenter.class.getSimpleName());

    private DownloadTransContract.View mView;

    public RiskTradePresenter(@NonNull DownloadTransContract.View view, @NonNull DataSource repository) {
        super(view, repository);
        mView = checkNotNull(view);
    }

    @Override
    protected TransData getTransData() {
        TransData transData = new TransData();
        transData.setTransType(TransType.RISKTRADE);
        return transData;
    }

    @Override
    protected void onFirstAction() {
        TimerTask task = new TimerTask() {
            @Override
            public void run() {
                postMainThread(() -> mView.showOnlineProc(mTransData, null));
            }
        };
        Timer timer = new Timer();
        timer.schedule(task, 1000);//1秒后执行TimeTask的run方法

    }
    @Override
    protected void onTransSuccess(RecvData recvData) {
        postMainThread(() -> mView.showTransSuccess());
    }
}
